﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using CPF.Drawing;

namespace CPFUI.IHelper
{
    public class BitMapHelper
    {

        /// <summary>
        /// 获取本地图片
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static Image GetBitMap(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return null;
            }

            FileStream filestream = new FileStream(filePath, FileMode.Open, FileAccess.Read);

            int bytelength = (int)filestream.Length;
            byte[] filebytes = new byte[bytelength];
            filestream.Read(filebytes, 0, bytelength);

            //文件流关閉,文件解除锁定
            filestream.Close();

            return Image.FromStream(new MemoryStream(filebytes));
        }
    }
}
